function [ Impedence ] = ImpedenceCalcGUI( P_Harmonics, F_Harmonics, Plots )
%ImpedenceCalc Caclulates the impedence specturm for inputed Pressure and
%flow harmonics
%   This script will caclulate and plot the impedence spectrum for 
% fourier harmonics that are imputed into the script. Define Plot as true
% for a plot output of the resultsing impedences.

%% This reduces the Harmonics such that we only look up to the max of the smaller one

temp_p = size(P_Harmonics,1);
temp_f = size(F_Harmonics,1);

if temp_p < temp_f
    F_Harmonics = F_Harmonics(1:temp_p,:);
else
    P_Harmonics = P_Harmonics(1:temp_f,:);
end



%% Calculate Modulus and Phase

Modulus = calculateModulus(P_Harmonics(:,2), F_Harmonics(:,2)); % Pressure over Flow

Phase = calculatePhase(F_Harmonics(:,3), P_Harmonics(:,3)); % Phase of Flow - Phase of Pressure



%% Plotting

Harmonic = 0:length(Modulus)-1; % Create Vector of Harmonics for Plots

Impedence = [Harmonic' Modulus Phase];

if Plots == true
    

    % Plot of all harmonics
    % Modulus
    subplot(2,2,1)
    plot(Harmonic, Modulus, 'o--' )
    xlabel('Harmonic')
    ylabel('Modulus (dynes*s/cm^3)')
    title('Modulus - Full Spectrum')
    
    % Phase
    subplot(2,2,2)
    plot(Harmonic, Phase, 'o--')
    xlabel('Harmonic')
    ylabel('Phase (rads)')
    title('Phase - Full Spectrum')
    
    % Zoom plot of only harmonics 0-6
    % Modulus
    subplot(2,2,3)
    plot(Harmonic, Modulus, 'o--' )
    xlabel('Harmonic')
    ylabel('Modulus (dynes*s/cm^3)')
    xlim([0,6])
    title('Modulus - Zoomed')
    
    % Phase
    subplot(2,2,4)
    plot(Harmonic, Phase, 'o--')
    xlabel('Harmonic')
    ylabel('Phase (rads)')
    xlim([0,6])
    title('Phase - Zoomed')
    suptitle('Impedence Plots')
    
    set(gcf, 'Visible', 'off')
end

